﻿@{
    ViewBag.Title = "发票管理审核";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section Scripts{
    <script type="text/javascript">
        //new 数组
        var Materials = new Array();
        //页面加载
        $(document).ready(function () {
            DisableBackspace();
            $.InitDateTime();

            $('#txtIFCheck').combobox({
                valueField: 'ID',
                textField: 'Name',
                method: 'get',
                editable: false,
                panelHeight: 'auto',
                data: [
                {
                    ID: '',
                    Name: '全部'
                },
                {
                    ID: "true",
                    Name: '是'
                },
                {
                    ID: "false",
                    Name: '否'
                }
                ]
            });


            //绑定问所有查询条件，执行查询
            bindGrid();

            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridDeliveryList2");

        });
        //页面动态改动
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridDeliveryList2");
        });
        //重新查询
        function reSearch() {
            $("#gridDeliveryList2").datagrid({
                pageNumber: 1,//20151105增加点击查询按钮返回第一页
                queryParams: {
                    StartDate: $('#StartDate').datebox('getValue'),
                    EndDate: $('#EndDate').datebox('getValue'),

                    IFCheck: $('#txtIFCheck').combobox('getValue')
                }
            });

        }

        function bindGrid() {
            $("#gridDeliveryList2").datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                striped: true,
                singleSelect: false,
                url: '@Url.Content("~/IM/I_InvoiceManage/DataLoad2")',
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 15,//设置 页容量5为
                pageList: [10, 15, 20],//设置 页容量下拉框
                queryParams: {
                    StartDate: $('#StartDate').datebox('getValue'),
                    EndDate: $('#EndDate').datebox('getValue'),
                    IFCheck: $('#txtIFCheck').combobox('getValue')
                },
                //{"MaterialMTypeID":"MaterialType-16","MaterialName":"硝酸甘油针","MaterialManufacturer":"","MaterialVendor":"","MaterialAlarmCounts":0,"MaterialSpecification":"5mg","MaterialRealPrice":4.0000,"MaterialUnit":"MatertalUnit-7","MaterialUnitName":"支","EntryStorageName":"装备科仓库","TargetStorageName":"东区仓库","OperatorName":"管理员","ConsigneeID":"4","Remark":"","DeliveryType":"MatertalOutType-1","DeliveryTypeName":"直接出库单","DeliveryDetailCode":"2015051417145041","DeliveryCode":"201505141714504","RealBatchNo":"20190920","BatchNo":"24520161129","DeliveryTime":"\/Date(1431594889200)\/","OperatorCode":4,"EntryStorageCode":"00002","TargetStorageCode":"10001","TargetEntryDetailCode":"2015051417145041","DetailRemark":"","RedDeliveryDetailCode":null,"MaterialID":245}
                columns: [[
                   { field: 'ck', checkbox: true },
                   { title: '发票号', field: 'InvoiceNumber', width: '12%', sortable: false },
                   { title: '患者姓名', field: 'PatientName', width: '8%', sortable: false },
                   { title: '收费公里', field: 'ChargeKM', width: '5%', sortable: false },
                   { title: '救护车费', field: 'CarFee', width: '5%', sortable: false },
                     { title: '摆渡费', field: 'baidufei', width: '5%', sortable: false },
                    { title: '等车费', field: 'WaitingFee', width: '5%', sortable: false },

                        { title: '院前急救费', field: 'EmergencyFee', width: '5%', sortable: false },
                   { title: '药费', field: 'DrugFeeTotal', width: '5%', sortable: false },
                   { title: '检查费', field: 'ExamineFeeTotal', width: '5%', sortable: false },
                   { title: '材料费', field: 'ConsumableFeeTotal', width: '6%', sortable: false },
                   { title: '治疗费', field: 'MeasureFeeTotal', width: '6%', sortable: false },
                   { title: '应收合计', field: 'ReceivableTotal', width: '7%', sortable: false },
                   { title: '实收合计', field: 'PaidMoney', width: '8%', sortable: false },
                    { title: 'TaskCode', field: 'TaskCode', hidden: true },


                     {
                         title: '是否审核', field: 'IFCheck', width: '6%', sortable: false,
                         formatter: function (value, rowData, rowIndex) {
                             if (value == true) {
                                 return "是";
                             }
                             else {
                                 return "否";
                             }
                         }
                     },
                      { title: '审核时间', field: 'CheckTime', width: '10%', sortable: false, formatter: $.formatTime }
                ]],

                toolbar: [
                    {
                        id: 'btnPostCheck',
                        text: '已勾选[0]行,点击审批',
                        iconCls: 'icon-custom-View',
                        handler: function () {
                            var selected = $('#gridDeliveryList2').datagrid('getSelected');
                            if (selected) {
                                submitCheckDetail();

                            } else {
                                $.messager.alert('提示', '请选择数据行', 'info', function () {
                                });
                            }
                        }
                    }
                ],  //2016-4-11 新增出库审批功能  将选中的row注入到数组 Materials 中
                onCheck: function (index, row) {
                    if (Materials.length == 0) {
                        Materials.push(row);
                        changeRevisitViewNum();
                        return;
                    }
                    var boolContain = false;
                    $.each(Materials, function (i, info) {
                        if (info.TaskCode == row.TaskCode) {
                            boolContain = true;
                        }
                    });
                    if (!boolContain) {
                        Materials.push(row);
                    }
                    changeRevisitViewNum();

                },
                onUncheck: function (index, row) {
                    var obj;
                    $.each(Materials, function (i, info) {
                        if (info.TaskCode == row.TaskCode) {
                            obj = info;
                        }
                    });
                    Materials.remove(obj);
                    changeRevisitViewNum();
                },
                onCheckAll: function (rows) {
                    $.each(rows, function (i, infos) {

                        var hasmates = false;
                        $.each(Materials, function (index, mates) {
                            if (infos.TaskCode == mates.TaskCode) {
                                hasmates = true;
                            }
                        });
                        if (!hasmates)
                        { Materials.push(infos); }
                    }
                    );
                    changeRevisitViewNum();
                },
                onUncheckAll: function (rows) {
                    var obj;
                    $.each(rows, function (i, infos) {
                        $.each(Materials, function (index, mates) {
                            if (infos.TaskCode == mates.TaskCode) {
                                obj = infos;
                            }
                        });
                        Materials.remove(obj);

                        changeRevisitViewNum();
                    });
                },
                onLoadSuccess: function (data) {
                    $.messager.show({
                        title: '系统提示',
                        msg: '   成功加载出 ' + data.total + ' 条任务信息！'
                    });

                    setViewNumCheck();
                }
            });  //datagrid end



        } //bindGrid end

        //自动勾选已经存在的内容
        function setViewNumCheck() {
            var rows = $('#gridDeliveryList2').datagrid('getRows');
            $.each(rows, function (index, item) {
                $.each(Materials, function (i, info) {
                    if (item.TaskCode == info.TaskCode) {
                        $('#gridDeliveryList2').datagrid('checkRow', index);
                    }
                });
            });
        }


        //改变显示数量
        function changeRevisitViewNum() {
            if (Materials.length == 0) {
                $("#btnPostCheck").linkbutton({
                    text: "已勾选[" + Materials.length + "]行,点击审批",
                    iconCls: "icon-custom-cGoods"
                });
            } else if (Materials.length > 0) {
                $("#btnPostCheck").linkbutton({
                    text: "已勾选[<strong><span style='color:red'>" + Materials.length + "</span></strong>]行,点击审批",
                    iconCls: "icon-custom-cGoodsFull"
                });
            }
        }


        //提交审核结果  2016-4-11
        function submitCheckDetail() {

            var jsData = new Array();
            var i = 0;

            $(Materials).each(function () {
                var obj = new Object();

                obj.TaskCode = Materials[i].TaskCode;
                jsData.push(obj);
                i++;
            });

            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/IM/I_InvoiceManage/SavaPickCheck2")',
                data:
                    {

                        sDeliveryDetailInfo: JSON.stringify(jsData)
                    },
                dataType: "json",
                success: function (jsData) {
                    $.handleJsonResult(jsData, function () {
                        Materials.length = 0;
                        changeRevisitViewNum();
                        $('#gridDeliveryList2').datagrid('reload');

                    }

                    );
                }
            });


        }



    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'应收实收不等审核',iconCls:'icon-custom-cChuKuDan'">
        <div id="SearchBar" data-options="region:'north'" style="overflow: hidden; padding: 10px">
            <table>
                <tr>
                    <td>查询时间：</td>
                    <td colspan="3">
                        <input id="StartDate" class="easyui-datetimebox" style="width:150px" data-options="required:true" />
                        &nbsp;&nbsp;至&nbsp;
                        <input id="EndDate" class="easyui-datetimebox" style="width:150px" data-options="required:true" />
                    </td>

                    <td>是否审核:</td>
                    <td>
                        <input id="txtIFCheck" class="easyui-combobox" style="width:100px" />
                    </td>
                    <td>


                        &nbsp;&nbsp;
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>

                </tr>

            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="gridDeliveryList2"></table>
        </div>
    </div>
</div>

